package com.qd.pandaparkflow.compment.park;

import com.qd.pandaparkflow.bean.PriceReqVO;
import com.qd.pandaparkflow.context.PriceContext;
import com.yomahub.liteflow.core.NodeComponent;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import java.time.Duration;
import java.util.ArrayList;

/**
 * 初始化组件
 */
@ConditionalOnProperty(prefix = "liteflow", name = "enable", havingValue = "true")
@Component("initCmp")
public class InitComponent extends NodeComponent {
    @Override
    public void process() throws Exception {
        PriceReqVO req = this.getRequestData();
        PriceContext context = this.getContextBean(PriceContext.class);
        context.setOrderNo(req.getOrderNo());
        context.setStartTime(req.getStartTime());
        context.setEndTime(req.getEndTime());
        context.setRules(req.getRules());
        context.setBillRule(req.getBillRule());
        context.setPrintLog(new ArrayList<>(16));
        final Duration duration = Duration.between(req.getStartTime(), req.getEndTime());
        final long minutes = duration.toMinutes();
        context.setMinutes(minutes);
    }

    @Override
    public boolean isAccess() {
        PriceReqVO req = this.getSlot().getRequestData();
        return req != null;
    }
}
